﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace InputLibs
{
    public class InputLab
    {
        private string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _surName;

        public string SurName
        {
            get { return _surName; }
            set { _surName = value; }
        }

        private string _id;

        public string ID
        {
            get { return _id; }
            set { _id = value; }
        }


        private int _age;

        public int Age
        {
            get { return _age; }
            set { _age = value; }
        }

        private int _weight;

        public int Weight
        {
            get { return _weight; }
            set { _weight = value; }
        }


        private int _height;

        public int Height
        {
            get { return _height; }
            set { _height = value; }
        }

        private string _desc;

        public string Desc
        {
            get { return _desc; }
            set { _desc = value; }
        }

        private List<InputRow> _firstFile;

        public List<InputRow> FirstFile
        {
            get { return _firstFile; }
            set { _firstFile = value; }
        }

        private List<InputRow> _secondFile;

        public List<InputRow> SecondFile
        {
            get { return _secondFile; }
            set { _secondFile = value; }
        }


        private List<InputRow> _thirdFile;

        public List<InputRow> ThirdFile
        {
            get { return _thirdFile; }
            set { _thirdFile = value; }
        }

        private List<InputRow> _forthFile;

        public List<InputRow> ForthFile
        {
            get { return _forthFile; }
            set { _forthFile = value; }
        }

        private List<InputRow> _fifthFile;

        public List<InputRow> FiFthFile
        {
            get { return _fifthFile; }
            set { _fifthFile = value; }
        }

        private List<InputRow> _sixthFile;

        public List<InputRow> SixthFile
        {
            get { return _sixthFile; }
            set { _sixthFile = value; }
        }


        private string _firstFileStr;

        public string FirstFileStr
        {
            get { return _firstFileStr; }
            set { _firstFileStr = value; }
        }

        private string _secondFileStr;

        public string SecondFileStr
        {
            get { return _secondFileStr; }
            set { _secondFileStr = value; }
        }

        private string _thirdFileStr;

        public string ThirdFileStr
        {
            get { return _thirdFileStr; }
            set { _thirdFileStr = value; }
        }

        private string _forthFileStr;

        public string ForthFileStr
        {
            get { return _forthFileStr; }
            set { _forthFileStr = value; }
        }

        private string _fifthFileStr;

        public string FiFthFileStr
        {
            get { return _fifthFileStr; }
            set { _fifthFileStr = value; }
        }

        private string _sixthFileStr;

        public string SixthFileStr
        {
            get { return _sixthFileStr; }
            set { _sixthFileStr = value; }
        }

        public List<InputRow> GetRight()
        {
            List<InputRow> rights = new List<InputRow>();
            int i = 0;
            foreach (InputRow item in _firstFile)
            {
                InputRow input = new InputRow();
                input.Id = item.Id;
                input.First = item.Second;
                input.Second = item.Third;
                input.Third = item.First;

                input.Forth = _secondFile[i].Second;
                input.FiFth = _secondFile[i].Third;
                input.Sixth = _secondFile[i].First;

                input.Seventh = _thirdFile[i].Second;
                input.Eigth = _thirdFile[i].Third;
                input.Ninth = _thirdFile[i].First;

                rights.Add(input);

                ++i;
            }

            return rights;
        }

        public List<InputRow> GetLeft()
        {
            List<InputRow> lefts = new List<InputRow>();
            int i = 0;
            foreach (InputRow item in _forthFile)
            {
                InputRow input = new InputRow();
                input.Id = item.Id;
                input.First = item.Second;
                input.Second = item.Third;
                input.Third = item.First;

                input.Forth = _fifthFile[i].Second;
                input.FiFth = _fifthFile[i].Third;
                input.Sixth = _fifthFile[i].First;

                input.Seventh = _sixthFile[i].Second;
                input.Eigth = _sixthFile[i].Third;
                input.Ninth = _sixthFile[i].First;

                lefts.Add(input);

                ++i;
            }

            return lefts;
        }


        public bool ReadRight()
        {

            ReadInput1();
            ReadInput2();
            ReadInput3();

            return true;
        }

        public bool ReadLeft()
        {

            ReadInput4();
            ReadInput5();
            ReadInput6();

            return true;
        }



        private void ReadInput1()
        {
            StreamReader sr = new StreamReader(_firstFileStr);
            List<InputRow> firstInputs = new List<InputRow>();
            string strline = "";
            string[] _values = null;
            while (!sr.EndOfStream)
            {
                //x++;
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length == 4 )
                {
                    InputRow row = ExtractRow(_values);
                    firstInputs.Add(row);
                }
            }

            this.FirstFile = firstInputs;

            sr.Close();
        }

        private static InputRow ExtractRow(string[] _values)
        {
            InputRow row = new InputRow();
            row.Id = Convert.ToInt32(_values[0]);
            row.First = Convert.ToDouble(_values[1]);
            row.Second = Convert.ToDouble(_values[2]);
            row.Third = Convert.ToDouble(_values[3]);
            return row;
        }
        private void ReadInput2()
        {
            StreamReader sr = new StreamReader(_secondFileStr);
            List<InputRow> secondInputs = new List<InputRow>();
            string strline = "";
            string[] _values = null;
            while (!sr.EndOfStream)
            {
                //x++;
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length == 4)
                {
                    InputRow row = ExtractRow(_values);
                    secondInputs.Add(row);
                }
            }

            this.SecondFile = secondInputs;

            sr.Close();
        }

        private void ReadInput3()
        {
            StreamReader sr = new StreamReader(_thirdFileStr);
            List<InputRow> thirdInputs = new List<InputRow>();
            string strline = "";
            string[] _values = null;
            while (!sr.EndOfStream)
            {
                //x++;
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length == 4)
                {
                    InputRow row = ExtractRow(_values);
                    thirdInputs.Add(row);
                }
            }

            this.ThirdFile = thirdInputs;

            sr.Close();
        }

        private void ReadInput4()
        {
            StreamReader sr = new StreamReader(_forthFileStr);
            List<InputRow> forthInputs = new List<InputRow>();
            string strline = "";
            string[] _values = null;
            while (!sr.EndOfStream)
            {
                //x++;
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length == 4)
                {
                    InputRow row = ExtractRow(_values);
                    forthInputs.Add(row);
                }
            }

            this.ForthFile = forthInputs;

            sr.Close();
        }


        private void ReadInput5()
        {
            StreamReader sr = new StreamReader(_fifthFileStr);
            List<InputRow> fifthInputs = new List<InputRow>();
            string strline = "";
            string[] _values = null;
            while (!sr.EndOfStream)
            {
                //x++;
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length == 4)
                {
                    InputRow row = ExtractRow(_values);
                    fifthInputs.Add(row);
                }
            }

            this.FiFthFile = fifthInputs;

            sr.Close();
        }


        private void ReadInput6()
        {
            StreamReader sr = new StreamReader(_sixthFileStr);
            List<InputRow> sixthInputs = new List<InputRow>();
            string strline = "";
            string[] _values = null;
            while (!sr.EndOfStream)
            {
                //x++;
                strline = sr.ReadLine();
                _values = strline.Split(',');
                if (_values.Length == 4)
                {
                    InputRow row = ExtractRow(_values);
                    sixthInputs.Add(row);
                }
            }

            this.SixthFile = sixthInputs;

            sr.Close();
        }
        
     

    }
}
